# Maintainer: Ignacio Casal Quinteiro <icq@gnome.org>

_realname=json-glib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.10.6
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
pkgdesc="JSON-GLib implements a full suite of JSON-related tools using GLib and GObject (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-python-docutils")
license=('spdx:LGPL-2.1-or-later')
url="https://gnome.pages.gitlab.gnome.org/json-glib/"
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz")
sha256sums=('77f4bcbf9339528f166b8073458693f0a20b77b7059dbc2db61746a1928b0293')
msys2_repository_url="https://gitlab.gnome.org/GNOME/json-glib"
noextract=("${_realname}-${pkgver}.tar.xz")

prepare() {
  bsdtar -xf "${_realname}-${pkgver}.tar.xz" || bsdtar -xf "${_realname}-${pkgver}.tar.xz" || true
  cd "${srcdir}"/${_realname}-${pkgver}
}

build() {
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson setup \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --buildtype plain \
    -Dman=true \
    -Dinstalled_tests=false \
    -Ddocumentation=disabled \
    "build-${MSYSTEM}" \
    "${_realname}-${pkgver}"

  meson compile -C "build-${MSYSTEM}"
}

check() {
  meson test -C "build-${MSYSTEM}" || warning "Tests failed"
}

package() {
  meson install -C "build-${MSYSTEM}" --destdir "${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
